package com.ukao.pad.ui.splash;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ukao.pad.R;
import com.ukao.pad.base.BaseFragment;
import com.ukao.pad.bean.SearchHistorysBean;
import com.ukao.pad.db.SearchHistoryDao;
import com.ukao.pad.ui.LoginActivity;
import com.ukao.pad.utils.AppManager;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 开始使用
 */
public class StartUseFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.bring_into_use)
    TextView bringIntoUse;
    Unbinder unbinder;


    private String mParam1;
    private String mParam2;
    private SearchHistoryDao dao;
    private ArrayList<SearchHistorysBean> historywordsList;


    public static StartUseFragment newInstance(String param1, String param2) {
        StartUseFragment fragment = new StartUseFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_start_use, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    @Override
    protected void initView() {
        dao= new SearchHistoryDao(_mActivity);
        historywordsList= dao.findAll();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.bring_into_use)
    public void onViewClicked() {
        dao.addOrUpdate("first");
        Intent  mIntent=new Intent(_mActivity, LoginActivity.class);
        startActivity(mIntent);
        AppManager.getAppManager().finishActivity(SplashActivity.class);

    }
}
